package com.audaque.springboot.foshanupload.pagehelper.component;

import com.audaque.springboot.foshanupload.core.model.qo.page.Page;
import com.audaque.springboot.foshanupload.pagehelper.uitl.MybatisPageHelperPageConvertUtil;
import com.github.pagehelper.PageInfo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * @author zgb
 * @desc ...
 * @date 2023-01-25 11:42:52
 */

@Mapper(componentModel = "spring", imports = {MybatisPageHelperPageConvertUtil.class})
public interface MybatisPageHelperPageConvert {
    @Mappings({
            @Mapping(target = "page", source = "pager.pageNum"),   //int
            @Mapping(target = "rows", source = "pager.pageSize"),  //int
            @Mapping(target = "offset", expression = "java(new Integer(new Long((pager.getPageNum()-1)/pager.getPageSize()).intValue()))"),   //long
            @Mapping(target = "limit", expression = "java(new Integer(new Long(pager.getPageSize()).intValue()))"),    //long
            @Mapping(target = "total", source = "pager.total")  //int


    })
    Page pager2Page(PageInfo pager);


}

